﻿function getQuerystring(key) {
  var qs = document.location.search;
  if (qs.length > 0) {
    qs = qs.substring(1);
  }
  var keys = qs.split("&");
  for (var k in keys) {
    var pair = keys[k].split("=", 2);
    if (pair[0] == key) {
      return pair[1];
    }
  }
  return "";
}

function sendRedirect(redirect) {
  chrome.extension.sendRequest(
    {
      request: "popup",
      redirect: redirect,
      site: getQuerystring('site'),
      tabId: parseInt(getQuerystring("tabId")),
      hostname: getQuerystring("hostname")
    }, function() { window.close() });
}